<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>tango.io.selector.SelectSelector</title>
  <link href="./css/style.css" rel="stylesheet" type="text/css"/>
  <!-- <link href="./img/icon.png" rel="icon" type="image/png"/> -->
  <script type="text/javascript" src="./js/jquery.js"></script>
  <script type="text/javascript" src="./js/modules.js"></script>
  <script type="text/javascript" src="./js/quicksearch.js"></script>
  <script type="text/javascript" src="./js/navigation.js"></script>
  <!--<script type="text/javascript" src="./js/jquery.treeview.js"></script>-->
  <script type="text/javascript">
    var g_moduleFQN = "tango.io.selector.SelectSelector";
  </script>
  
</head>
<body>
<div id="content">
  <h1><a href="./htmlsrc/tango.io.selector.SelectSelector.html" class="symbol">tango.io.selector.SelectSelector</a></h1>
  
<p class="sec_header">License:</p>BSD style: see <a href="http://www.dsource.org/projects/tango/wiki/LibraryLicense">license.txt</a>
<p class="sec_header">Author:</p>Juan Jose Comellas <juanjo@comellas.com.ar>
<dl>
<dt class="decl">class <a class="symbol _class" name="SelectSelector" href="./htmlsrc/tango.io.selector.SelectSelector.html#L81" kind="class" beg="81" end="553">SelectSelector</a> : AbstractSelector; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#SelectSelector" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L81">#</a></dt>
<dd class="ddef">
<div class="summary">Selector that uses the select() system call to receive I/O events for
 the registered conduits. To use this class you would normally do
 something like this:</div>
<p class="sec_header">Examples:</p><pre class="d_code">
<span class="k">import</span> <span class="i">tango</span>.<span class="i">io</span>.<span class="i">selector</span>.<span class="i">SelectSelector</span>;

<span class="i">Socket</span> <span class="i">socket</span>;
<span class="i">ISelector</span> <span class="i">selector</span> = <span class="k">new</span> <span class="i">SelectSelector</span>();

<span class="i">selector</span>.<span class="i">open</span>(<span class="n">100</span>, <span class="n">10</span>);

<span class="lc">// Register to read from socket</span>
<span class="i">selector</span>.<span class="i">register</span>(<span class="i">socket</span>, <span class="i">Event</span>.<span class="i">Read</span>);

<span class="k">int</span> <span class="i">eventCount</span> = <span class="i">selector</span>.<span class="i">select</span>(<span class="n">0.1</span>); <span class="lc">// 0.1 seconds</span>
<span class="k">if</span> (<span class="i">eventCount</span> &gt; <span class="n">0</span>)
{
    <span class="lc">// We can now read from the socket</span>
    <span class="i">socket</span>.<span class="i">read</span>();
}
<span class="k">else</span> <span class="k">if</span> (<span class="i">eventCount</span> == <span class="n">0</span>)
{
    <span class="lc">// Timeout</span>
}
<span class="k">else</span> <span class="k">if</span> (<span class="i">eventCount</span> == -<span class="n">1</span>)
{
    <span class="lc">// Another thread called the wakeup() method.</span>
}
<span class="k">else</span>
{
    <span class="lc">// Error: should never happen.</span>
}

<span class="i">selector</span>.<span class="i">close</span>();
</pre>
<dl>
<dt class="decl">alias AbstractSelector.select <a class="symbol _alias" name="SelectSelector.select" href="./htmlsrc/tango.io.selector.SelectSelector.html#L87" kind="alias" beg="87" end="87">select</a>; <a title="Permalink to this symbol" href="#SelectSelector.select" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L87">#</a></dt>
<dd class="ddef">
<div class="summary">Alias for the select() method as we're not reimplementing it in
 this class.</div></dd>
<dt class="decl">uint <a class="symbol _variable" name="SelectSelector.DefaultSize" href="./htmlsrc/tango.io.selector.SelectSelector.html#L114" kind="variable" beg="114" end="114">DefaultSize</a>; <span class="attrs">[<span class="prot">public</span>, <span class="stc">const</span>]</span> <a title="Permalink to this symbol" href="#SelectSelector.DefaultSize" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L114">#</a></dt>
<dd class="ddef">
<div class="summary">Default number of SelectionKey's that will be handled by the
 SelectSelector.</div></dd>
<dt class="decl">void <a class="symbol _function" name="SelectSelector.open" href="./htmlsrc/tango.io.selector.SelectSelector.html#L127" kind="function" beg="127" end="135">open</a><span class="params">(uint <em>size</em> = DefaultSize, uint <em>maxEvents</em> = DefaultSize)</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#SelectSelector.open" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L127">#</a></dt>
<dd class="ddef">
<div class="summary">Open the select()-based selector.</div>
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>size</em></td><td>maximum amount of conduits that will be registered;
                it will grow dynamically if needed.</td></tr>
<tr><td><em>maxEvents</em></td><td>maximum amount of conduit events that will be
                returned in the selection set per call to select();
                this value is currently not used by this selector.</td></tr></table></dd>
<dt class="decl">void <a class="symbol _function" name="SelectSelector.close" href="./htmlsrc/tango.io.selector.SelectSelector.html#L143" kind="function" beg="143" end="153">close</a><span class="params">()</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#SelectSelector.close" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L143">#</a></dt>
<dd class="ddef">
<div class="summary">Close the selector.</div>
<p class="sec_header">Remarks:</p>It can be called multiple times without harmful side-effects.</dd>
<dt class="decl">void <a class="symbol _function" name="SelectSelector.register" href="./htmlsrc/tango.io.selector.SelectSelector.html#L176" kind="function" beg="176" end="238">register</a><span class="params">(ISelectable <em>conduit</em>, Event <em>events</em>, Object <em>attachment</em> = null)</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#SelectSelector.register" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L176">#</a></dt>
<dd class="ddef">
<div class="summary">Associate a conduit to the selector and track specific I/O events.</div>
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>conduit</em></td><td>conduit that will be associated to the selector;
                must be a valid conduit (i.e. not null and open).</td></tr>
<tr><td><em>events</em></td><td>bit mask of Event values that represent the events
                that will be tracked for the conduit.</td></tr>
<tr><td><em>attachment</em></td><td>optional object with application-specific data that
                will be available when an event is triggered for the
                conduit</td></tr></table>
<p class="sec_header">Throws:</p>RegisteredConduitException if the conduit had already been
 registered to the selector.
<p class="sec_header">Examples:</p><pre class="d_code">
<span class="i">selector</span>.<span class="i">register</span>(<span class="i">conduit</span>, <span class="i">Event</span>.<span class="i">Read</span> | <span class="i">Event</span>.<span class="i">Write</span>, <span class="i">object</span>);
</pre></dd>
<dt class="decl">void <a class="symbol _function" name="SelectSelector.reregister" href="./htmlsrc/tango.io.selector.SelectSelector.html#L266" kind="function" beg="266" end="337">reregister</a><span class="params">(ISelectable <em>conduit</em>, Event <em>events</em>, Object <em>attachment</em> = null)</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#SelectSelector.reregister" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L266">#</a></dt>
<dd class="ddef">
<div class="summary">Modify the events that are being tracked or the 'attachment' field
 for an already registered conduit.</div>
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>conduit</em></td><td>conduit that will be associated to the selector;
                must be a valid conduit (i.e. not null and open).</td></tr>
<tr><td><em>events</em></td><td>bit mask of Event values that represent the events
                that will be tracked for the conduit.</td></tr>
<tr><td><em>attachment</em></td><td>optional object with application-specific data that
                will be available when an event is triggered for the
                conduit</td></tr></table>
<p class="sec_header">Remarks:</p>The 'attachment' member of the SelectionKey will always be
 overwritten, even if it's null.
<p class="sec_header">Throws:</p>UnregisteredConduitException if the conduit had not been previously
 registered to the selector.
<p class="sec_header">Examples:</p><pre class="d_code">
<span class="i">selector</span>.<span class="i">reregister</span>(<span class="i">conduit</span>, <span class="i">Event</span>.<span class="i">Write</span>, <span class="i">object</span>);
</pre></dd>
<dt class="decl">void <a class="symbol _function" name="SelectSelector.unregister" href="./htmlsrc/tango.io.selector.SelectSelector.html#L354" kind="function" beg="354" end="408">unregister</a><span class="params">(ISelectable <em>conduit</em>)</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#SelectSelector.unregister" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L354">#</a></dt>
<dd class="ddef">
<div class="summary">Remove a conduit from the selector.</div>
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>conduit</em></td><td>conduit that had been previously associated to the
                selector; it can be null.</td></tr></table>
<p class="sec_header">Remarks:</p>Unregistering a null conduit is allowed and no exception is thrown
 if this happens.
<p class="sec_header">Throws:</p>UnregisteredConduitException if the conduit had not been previously
 registered to the selector.</dd>
<dt class="decl">int <a class="symbol _function" name="SelectSelector.select:2" href="./htmlsrc/tango.io.selector.SelectSelector.html#L432" kind="function" beg="432" end="525">select</a><span class="params">(TimeSpan <em>timeout</em>)</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#SelectSelector.select:2" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L432">#</a></dt>
<dd class="ddef">
<div class="summary">Wait for I/O events from the registered conduits for a specified
 amount of time.</div>
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>timeout</em></td><td>TimeSpan with the maximum amount of time that the
            selector will wait for events from the conduits; the
            amount of time is relative to the current system time
            (i.e. just the number of milliseconds that the selector
            has to wait for the events).</td></tr></table>
<p class="sec_header">Returns:</p>The amount of conduits that have received events; 0 if no conduits
 have received events within the specified timeout; and -1 if the
 wakeup() method has been called from another thread.
<p class="sec_header">Throws:</p>InterruptedSystemCallException if the underlying system call was
 interrupted by a signal and the 'restartInterruptedSystemCall'
 property was set to false; SelectorException if there were no
 resources available to wait for events from the conduits.</dd>
<dt class="decl">ISelectionSet <a class="symbol _function" name="SelectSelector.selectedSet" href="./htmlsrc/tango.io.selector.SelectSelector.html#L535" kind="function" beg="535" end="539">selectedSet</a><span class="params">()</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#SelectSelector.selectedSet" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L535">#</a></dt>
<dd class="ddef">
<div class="summary">Return the selection set resulting from the call to any of the
 select() methods.</div>
<p class="sec_header">Remarks:</p>If the call to select() was unsuccessful or it did not return any
 events, the returned value will be null.</dd>
<dt class="decl">SelectionKey <a class="symbol _function" name="SelectSelector.key" href="./htmlsrc/tango.io.selector.SelectSelector.html#L549" kind="function" beg="549" end="552">key</a><span class="params">(ISelectable <em>conduit</em>)</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#SelectSelector.key" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L549">#</a></dt>
<dd class="ddef">
<div class="summary">Return the selection key resulting from the registration of a
 conduit to the selector.</div>
<p class="sec_header">Remarks:</p>If the conduit is not registered to the selector the returned
 value will be null. No exception will be thrown by this method.</dd></dl></dd>
<dt class="decl">class <a class="symbol _class" name="SelectSelectionSet" href="./htmlsrc/tango.io.selector.SelectSelector.html#L558" kind="class" beg="558" end="629">SelectSelectionSet</a> : ISelectionSet; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#SelectSelectionSet" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L558">#</a></dt>
<dd class="ddef">
<div class="summary">SelectionSet for the select()-based Selector.</div>
</dd>
<dt class="decl">class <a class="symbol _class" name="HandleSet" href="./htmlsrc/tango.io.selector.SelectSelector.html#L642" kind="class" beg="642" end="797">HandleSet</a>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#HandleSet" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L642">#</a></dt>
<dd class="ddef">
<div class="summary">Helper class used by the select()-based Selector to store handles.
 On Windows the handles are kept in an array of uints and the first
 element of the array stores the array "length" (i.e. number of handles
 in the array). Everything is stored so that the native select() API
 can use the HandleSet without additional conversions by just casting it
 to a fd_set*.</div>
<dl>
<dt class="decl">uint <a class="symbol _variable" name="HandleSet.DefaultSize" href="./htmlsrc/tango.io.selector.SelectSelector.html#L645" kind="variable" beg="645" end="645">DefaultSize</a>; <span class="attrs">[<span class="prot">public</span>, <span class="stc">const</span>]</span> <a title="Permalink to this symbol" href="#HandleSet.DefaultSize" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L645">#</a></dt>
<dd class="ddef">
<div class="summary">Default number of handles that will be held in the HandleSet.</div></dd>
<dt class="decl"><a class="symbol _ctor" name="HandleSet.this" href="./htmlsrc/tango.io.selector.SelectSelector.html#L653" kind="ctor" beg="653" end="657">this</a><span class="params">(uint <em>size</em> = DefaultSize)</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#HandleSet.this" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L653">#</a></dt>
<dd class="ddef">
<div class="summary">Constructor. Sets the initial number of handles that will be held
 in the HandleSet.</div></dd>
<dt class="decl">uint <a class="symbol _function" name="HandleSet.length" href="./htmlsrc/tango.io.selector.SelectSelector.html#L662" kind="function" beg="662" end="665">length</a><span class="params">()</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#HandleSet.length" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L662">#</a></dt>
<dd class="ddef">
<div class="summary">Return the number of handles present in the HandleSet.</div></dd>
<dt class="decl">void <a class="symbol _function" name="HandleSet.reset" href="./htmlsrc/tango.io.selector.SelectSelector.html#L670" kind="function" beg="670" end="673">reset</a><span class="params">()</span>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#HandleSet.reset" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L670">#</a></dt>
<dd class="ddef">
<div class="summary">Remove all the handles from the set.</div></dd>
<dt class="decl">void <a class="symbol _function" name="HandleSet.set" href="./htmlsrc/tango.io.selector.SelectSelector.html#L678" kind="function" beg="678" end="694">set</a><span class="params">(ISelectable.Handle <em>handle</em>)</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#HandleSet.set" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L678">#</a></dt>
<dd class="ddef">
<div class="summary">Add the handle to the set.</div></dd>
<dt class="decl">void <a class="symbol _function" name="HandleSet.clear" href="./htmlsrc/tango.io.selector.SelectSelector.html#L699" kind="function" beg="699" end="717">clear</a><span class="params">(ISelectable.Handle <em>handle</em>)</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#HandleSet.clear" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L699">#</a></dt>
<dd class="ddef">
<div class="summary">Remove the handle from the set.</div></dd>
<dt class="decl">HandleSet <a class="symbol _function" name="HandleSet.copy" href="./htmlsrc/tango.io.selector.SelectSelector.html#L722" kind="function" beg="722" end="733">copy</a><span class="params">(HandleSet <em>handleSet</em>)</span>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#HandleSet.copy" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L722">#</a></dt>
<dd class="ddef">
<div class="summary">Copy the contents of the HandleSet into this instance.</div></dd>
<dt class="decl">bool <a class="symbol _function" name="HandleSet.isSet" href="./htmlsrc/tango.io.selector.SelectSelector.html#L738" kind="function" beg="738" end="749">isSet</a><span class="params">(ISelectable.Handle <em>handle</em>)</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#HandleSet.isSet" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L738">#</a></dt>
<dd class="ddef">
<div class="summary">Check whether the handle has been set.</div></dd>
<dt class="decl">fd_set* <a class="symbol _function" name="HandleSet.opCast" href="./htmlsrc/tango.io.selector.SelectSelector.html#L755" kind="function" beg="755" end="758">opCast</a><span class="params">()</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#HandleSet.opCast" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/tango.io.selector.SelectSelector.html#L755">#</a></dt>
<dd class="ddef">
<div class="summary">Cast the current object to a pointer to an fd_set, to be used with the
 select() system call.</div></dd></dl></dd></dl>
</div>
<div id="footer">
  <p>Copyright (c) 2006 Juan Jose Comellas. All rights reserved</p>
  <p>Page generated by <a href="http://code.google.com/p/dil">dil</a> on Fri Dec 26 04:04:02 2008. Rendered by <a href="http://code.google.com/p/dil/wiki/Kandil">kandil</a>.</p>
</div>
</body>
</html>